using System;
using System.Web.Mvc;
using ZQNB.BaseLib.Core.Models;
using ZQNB.Web.Common.Contexts;

namespace ZQNB.Web.Areas.Cloud.Controllers
{
    public class AceController : Controller
    {
        private readonly NbSiteContext _nbSiteContext;

        public AceController(NbSiteContext nbSiteContext)
        {
            _nbSiteContext = nbSiteContext;
        }

        [OutputCache(NoStore = true, Duration = 0, VaryByParam = "*")]
        [HttpGet]
        public JsonResult GetAceSetting()
        {
            AceSetting aceSetting = _nbSiteContext.GetAceSetting();
            return Json(aceSetting, JsonRequestBehavior.AllowGet);
        }

        [HttpPost]
        public ActionResult SetAceSetting(string name, bool status)
        {
            AceSettingKey value;
            bool isOk = Enum.TryParse(name, true, out value);
            if (isOk)
            {
                AceSetting aceSetting = _nbSiteContext.GetAceSetting();
                switch (value)
                {
                    case AceSettingKey.navbar_fixed:
                        aceSetting.FixedNavbar = status;
                        break;
                    case AceSettingKey.sidebar_fixed:
                        aceSetting.FixedSidebar = status;
                        break;
                    case AceSettingKey.breadcrumbs_fixed:
                        aceSetting.FixedBreadcrumbs = status;
                        break;
                    case AceSettingKey.main_container_fixed:
                        aceSetting.InsideContainer = status;
                        break;
                    case AceSettingKey.sidebar_collapsed:
                        //aceSetting. = status;
                        break;
                    default:
                        throw new ArgumentOutOfRangeException();
                }

                _nbSiteContext.SaveAceSetting(aceSetting);
                return Json(true, JsonRequestBehavior.DenyGet);
            }

            return Json(false, JsonRequestBehavior.DenyGet);
        }
    }
}